package com.example.redisstudy;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.atomic.AtomicInteger;

public class MaterialCodeGenerator {
    private static final String PREFIX = "MA";
    private static final AtomicInteger COUNTER = new AtomicInteger(0);

    public static void main(String[] args) {
        // 测试代码
        MaterialCodeGenerator generator = new MaterialCodeGenerator();
        System.out.println(generator.getMaterialCode());
        System.out.println(generator.getMaterialCode());
    }

    private String getMaterialCode() {
        StringBuilder code = new StringBuilder(PREFIX);
        String timeStamp = new SimpleDateFormat("yyMMddHHmmss").format(new Date());
        int uniqueNumber = COUNTER.getAndIncrement();

        code.append(timeStamp).append(uniqueNumber);
        return code.toString();
    }
}
